package demo2;

import com.sun.corba.se.impl.orbutil.ObjectUtility;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-07-03
 * Time: 11:05
 */
class Money implements Cloneable{
    public double money;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    //public String name;
    public int age;
    public Money m = new Money();
    //public double score;

    public Student( int age) {
        //this.name = name;
        this.age = age;
        //this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //return super.clone();
        Student tmp = (Student)super.clone();
        //Money money = (Money) tmp.m.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
    }
}
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student(10);
        student1.m.money = 19.9;
        Student student2 = (Student) student1.clone();
        System.out.println(student1.m.money);
        System.out.println(student2.m.money);
        System.out.println("==========================");
        student1.m.money = 29.9;
        System.out.println(student1.m.money);
        System.out.println(student2.m.money);

    }
    public static void main1(String[] args)throws CloneNotSupportedException {
        Student student1 = new Student(10);
        Student student2 = (Student) student1.clone();
        System.out.println(student1);
        System.out.println(student2);
    }
}
